import instance from '../utils/http'
/**
 * 根据用户id查询收货地址
 * @param {} userid  
 */
export const reqAddressListByuserid = (userid) => {
    // 增加非空判断，避免传 undefined
    if (!userid) {
      return Promise.reject(new Error('userid 不能为空'));
    }
    return instance.get(`/address/selectAddressByUserid/?userid=${userid}`);
  };
  /**
   * 修改默认收货地址
   */
  export const updateDefaultAddress = (defaultaddress,addressid) => {
    // 增加非空判断，避免传 undefined
    if (!defaultaddress) {
      return Promise.reject(new Error('defaultaddress 不能为空'));
    }
    if (!addressid) {
        return Promise.reject(new Error('addressid 不能为空'));
      }
    return instance.post(`/address/updateDefaultAddress/?defaultaddress=${defaultaddress}&addressid=${addressid}`);
  };
  /**
 * 根据地址id查询收货地址
 * @param {} addressid  
 */
export const reqAddressByaddressid = (addressid) => {
    // 增加非空判断，避免传 undefined
    if (!addressid) {
      return Promise.reject(new Error('addressid 不能为空'));
    }
    return instance.get(`/address/selectAddressById/?addressid=${addressid}`);
  };
  /**
   * 修改地址
   * 传一个对象
   */
  export const reqUpdateAddress = (address) => {    
    return instance.post('/address/updateAddress',address);
  };

   /**
   * 新增地址
   * 传一个对象
   */
  export const reqAddAddress = (address) => {    
    return instance.post('/address/insertAddress',address);
  };

    /**
 * 根据地址id删除收货地址
 * @param {} addressid  
 */
export const DeleteByaddressid = (addressid) => {
    // 增加非空判断，避免传 undefined
    if (!addressid) {
      return Promise.reject(new Error('addressid 不能为空'));
    }
    return instance.post(`/address/deleteAddressById/?addressid=${addressid}`);
  };